﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using DeepEarth.BingMapsToolkit.Client.MapGeometry;
using Microsoft.Maps.MapControl.Core;
using DeepEarth.BingMapsToolkit.Client.Common.Entities;
using GisSharpBlog.NetTopologySuite.Geometries;
using System.Collections.Generic;

namespace SMIL.Geometry.Render
{
    public class Render : IRender  
    {
        const int POLYGONLINEWIDTH = 12;
        Dictionary<string, StyleSpecification> statusStyles;

        public Render()
        {
            //statusStyles = new Dictionary<string, StyleSpecification>();

            //statusStyles.Add("Avtal", new StyleSpecification()             
            //{
            //    ID = "Avtal",
            //    LineColour = "FF1B0AA5",
            //    LineWidth = 20,
            //    PolyFillColour = "CC5AC33D",
            //    ShowFill = true,
            //    ShowLine = true,
            //    IconURL = "http://kongo.swecosundsvall.se/portalplus/img/bus.png",
            //    IconScale = 1,
            //    PolygonLineColour = "FF2B2B2B",
            //    PolygonLineWidth = POLYGONLINEWIDTH
            //});

            //statusStyles.Add("Option", new StyleSpecification()
            //{
            //    ID = "Option",
            //    LineColour = "FF1BFFA5",
            //    LineWidth = 20,
            //    PolyFillColour = "CCC36D13D",
            //    ShowFill = true,
            //    ShowLine = true,
            //    PolygonLineColour = "FF2B2B2B",
            //    PolygonLineWidth = POLYGONLINEWIDTH,
            //});

            //statusStyles.Add("Förfrågan", new StyleSpecification()
            //{
            //    ID = "Förfrågan",
            //    LineColour = "FFFFFFA5",
            //    LineWidth = 20,
            //    PolyFillColour = "CC3D7EC3",
            //    ShowFill = true,
            //    ShowLine = true,
            //    PolygonLineColour= "FF2B2B2B",
            //    PolygonLineWidth = POLYGONLINEWIDTH,
            //});
        }

        private static GeoAPI.Geometries.IGeometry GetGeometryFromWKT(string wkt)
        {
            GisSharpBlog.NetTopologySuite.IO.WKTReader wktReader = new GisSharpBlog.NetTopologySuite.IO.WKTReader();
            GeoAPI.Geometries.IGeometry geometry = wktReader.Read(wkt);
            return geometry;
        }

        #region IRender Members

        public SelectGeometry RenderGeometry(MapCore map, EnhancedMapLayer layer, string itemID, string wkt, string status)
        {
            string _status = (statusStyles.ContainsKey(status)) ? status : "Förfrågan";

            var geom = GetGeometryFromWKT(wkt);

            SelectGeometry sg = new SelectGeometry(geom, statusStyles[_status], map, layer) { ItemID = itemID };
            
            return sg;
        }

        #endregion
    }
}
